package logic

import (
	"context"
	"gitcode.com/imCodeKing/user-service/model"

	"gitcode.com/imCodeKing/user-service/internal/svc"
	"gitcode.com/imCodeKing/user-service/pb"

	"github.com/zeromicro/go-zero/core/logx"
)

type GetUserLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGetUserLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetUserLogic {
	return &GetUserLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 获取用户信息
func (l *GetUserLogic) GetUser(in *pb.GetUserRequest) (*pb.GetUserResponse, error) {
	// todo: add your logic here and delete this line
	user, err := model.NewUsersModel(l.svcCtx.DB).FindOne(l.ctx, uint64(in.Id))
	if err != nil {
		return nil, err
	}
	return &pb.GetUserResponse{
		Name: user.Name,
	}, nil
}
